package com.znyj.cloud.chain.util;

import com.alibaba.fastjson.JSONObject;
import io.netty.handler.codec.http.HttpRequest;
import org.apache.commons.lang.StringUtils;

/**
 * Created by gaoliwei on 15-2-26.
 */
public class LogUtil {


    public static String buildRequestReponseLog(HttpRequest msg, JSONObject data, String response) {

        //记录请求
        StringBuilder requestInfo = new StringBuilder();
        requestInfo.append("RequestResponseLog\t");
        requestInfo.append(msg.getUri());
        requestInfo.append("\t");
        requestInfo.append(msg.headers().get("User-Agent"));
        requestInfo.append("\t");

        if (null != data) {
            requestInfo.append(data.toString());
            requestInfo.append("\t");
        }

        if (StringUtils.isNotEmpty(response)) {
            requestInfo.append(response);
        } else {
            requestInfo.append("not response put");
        }
        return requestInfo.toString();
    }
}
